package 观察者模式.JDK实现;

import 观察者模式.DisplayElement;

import java.util.Observable;
import java.util.Observer;

/**
 * @author zzs
 * @ClassName CurrentDisplay.java
 * @Description
 * @createTime 2022年05月10日 18:37:00
 */
public class CurrentDisplay implements Observer, DisplayElement {
    private String message;

    private Observable o;

    public CurrentDisplay(Observable o) {
        this.o = o;
        o.addObserver(this);
    }

    @Override
    public void display() {
        System.out.println(message);
    }


    @Override
    public void update(Observable o, Object arg) {
        if (o instanceof CurrentDate) {
            this.message = ((CurrentDate) o).getMessage();
            display();
        }
    }
}
